package homework21.studyplan.member;

import java.util.Scanner;

public class Member {
        private  String name;
        private  String sex;
        private  int age;
        private  int  memberNum;
        Scanner input = new Scanner(System.in);
    public Member() {
    }

    public Member(String name, String sex, int age) {
        this.setName(name);
        this.setSex(sex);
        this.setAge(age);
        this.setMemberNum();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        while (name.length() < 3){
            System.out.println("请重新输入姓名（长度大于或等于3）：");
            name = input.next();
        }
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        while ((!sex.equals("男")) && (!sex.equals("女"))){
            System.out.println("请重新输入性别：（男或女）");
            sex  = input.next();
        }
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        while (age < 18 || age > 40){
            System.out.println("请重新输入年龄（18到40之间）：");
            age  = input.nextInt();
        }
        this.age = age;
    }

    public int  getMemberNum() {
        return memberNum;
    }

    public void setMemberNum() {
        this.memberNum = (int)(Math.random() * (9999 - 1000 + 1) + 1000);
    }

    @Override
    public String toString() {
        return "会员的" +
                "姓名是" + name + "\t" +
                "性别是" + sex + "\t" +
                "年龄是" + age + "\t" +
                "会员号是" + memberNum ;
    }
}
